<?php

/**
 * Group Model for NiceAuth Plugin
 *
 * NiceAuth : User Authentication and Authorization Plugin for CakePHP
 * Copyright 2011, R.S.Martin (http://rsmartin.me)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author RSMartin
 * @copyright Copyright (c) 2011, RSMartin (http://rsmartin.me)
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 */
App::uses('NiceAuthAppModel', 'NiceAuth.Model');

class Group extends NiceAuthAppModel {

    var $name = 'Group';
    var $hasMany = array('User');
    var $actsAs = array('Acl' => array('type' => 'requester'));
    public $validate = array(
        'name' => array(
            'rule' => 'isUnique',
            'required' => true,
            'allowEmpty' => false,
            'message' => 'Grupo já existe'
        )
    );

    public function parentNode() {
        return null;
    }

    public function isAdmin($id) {
        $group = $this->findById($id);
        return ($group['Group']['isAdmin'] == 1);
    }

    
}